<template>
  <div class="l-from-body">
    <!--<el-alert class="l-from-el-alert" title="租户名称，先添加数据连接，与数据连接名称一样" type="warning"></el-alert>-->
    <el-form :model="formData" :rules="rules" size="mini" ref="form" label-width="88px">
      <el-col :span="24">
        <el-form-item label="数据连接" prop="f_DatabaseLinkId">
          <el-select v-model="formData.f_DatabaseLinkId" placeholder="请选择数据连接" @change="dblinkChange">
            <el-option v-for="item in dbArr" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="12">
        <el-form-item label="租户名称" prop="f_Name">
          <el-input v-model="formData.f_Name" :disabled="true"></el-input>
        </el-form-item>
      </el-col>

      <!--
            <el-col :span="24">
				<el-form-item label="租户类型" prop="f_TenantType">
				    <l-radio v-model="formData.f_TenantType" :options="[{value:0,label:'普通租户'},{value:1,label:'系统平台租户'}]" ></l-radio>
				</el-form-item>
            </el-col>
			-->

      <el-col :span="24">
        <el-form-item label="描述" prop="f_Description">
          <el-input type="textarea" v-model="formData.f_Remark"></el-input>
        </el-form-item>
      </el-col>
    </el-form>
  </div>
</template>
<script>
const api = window.$api.Tenant.tenantmanage;
//console.log(api);
export default {
  data() {
    return {
      dbArr: [],
      formData: {
        f_Id: "",
        f_Name: "",
        f_AdminName: "admin",
        f_Schema: "",
        f_Remark: "",
        f_CreateDate: "2022-06-30T02:48:51.757Z",
        f_ModifyDate: "2022-06-30T02:48:51.757Z",
        f_CreateUserId: "System",
        f_CreateUserName: "System",
        f_ModifyUserId: "",
        f_ModifyUserName: "",
        f_IsDeleted: 0,
        f_TenantType: 0,
        f_DatabaseLinkId: "",
      },
      rules: {
        f_Name: [{ required: true, message: "请输入名称" }],
        f_DatabaseLinkId: [{ required: true, message: "请选择数据连接" }],
      },
    };
  },
  computed: {},
  created() {
    var _this = this;
    api.dbList().then((res) => {
      //console.log(res.data.data);
      res.data.data.forEach(function (v) {
        v.label = v.f_DBName;
        v.value = v.f_DatabaseLinkId;
      });
      _this.dbArr = _this.$deepClone(res.data.data);
    });
    var time = this.format();
    //console.log(time);
    this.formData.f_CreateDate = time;
    this.formData.f_ModifyDate = time;
  },
  methods: {
    resetForm() {
      //this.formData.f_Id = '';
      this.$refs.form && this.$refs.form.resetFields();
    },
    // 校验表单
    validateForm() {
      return this.$formValidateWraper(this.$refs.form);
    },
    setForm(data) {
      //console.log("设置表单：");
      //console.log(data);
      this.formData = this.$deepClone(data);
    },
    getForm() {
      //console.log("获取表单：");
      let formData = this.$deepClone(this.formData);
      if (this.formData.f_Id) {
        //这里代码有错误
        //    let formData = {
        //       f_Remark: this.formData.f_Remark,
        //     };
      }
      return formData;
    },
    dblinkChange(e) {
      var _this = this;
      //console.log(e);
      //console.log(this.formData.f_DatabaseLinkId);
      _this.dbArr.forEach(function (v) {
        if (v.value == e) _this.formData.f_Name = v.label;
      });
    },

    //获取时间
    format() {
      function add0(m) {
        return m < 10 ? "0" + m : m;
      }
      var time = new Date();
      var y = time.getFullYear();
      var m = time.getMonth() + 1;
      var d = time.getDate();
      var h = time.getHours();
      var mm = time.getMinutes();
      var s = time.getSeconds();
      return y + "-" + add0(m) + "-" + add0(d) + " " + add0(h) + ":" + add0(mm) + ":" + add0(s);
    },
  },
};
</script>
<style scoped>
.l-from-el-alert {
  margin-bottom: 20px;
}
</style>
